<!--@reference Agile Web Development with Rails (4th Edition) (Whitney, Clare x11106131)
-->

<% if notice %>
    <p id= "notice"><%= notice %></p>
    <% end %>

<h1>Listing products</h1>

<table>
  <% @products.each do |product| %>
  <tr class="<%= cycle('list_line_odd', 'lost_line_even') %>">
    <td>
      <%= image_tag(product.image, :height=>"72px", :width=>"72px", :class => 'list_image') %>

    </td>

    <td class="list_description">
    <dl>
            <dt><%= product.name%></dt>
            <dd><%= truncate(strip_tags(product.description),
                    :length => 80) %></dd>
        </dl>
    </td>

    <td class="list_actions">
      <%= link_to 'Show', product %><br/>


           <%if current_user%>
           <%= button_to 'Add to Cart', line_items_path(:product_id => product), :remote => true %>

               <%if current_user.admin%>
              <%= link_to 'Edit', edit_product_path(product) %><br/>
                <%= link_to 'Destroy', product,
                    :confirm => 'Are you sure?',
                    :method => :delete %>
                <%end%>
                <%end%>






       <% end %>
</table>


<%= form_tag products_path, :method => 'get' do %>
    <p>
    <%= text_field_tag :search_query, params[:search_query] %>
    <%= submit_tag "Search", :name => nil %>
    </p>


<br/>

<%= link_to 'New Product', new_product_path %>

<%end%>
